// FrontEnd Plus GUI for JAD
// DeCompiled : HibernateColumn.class

package middlegen.plugins.hibernate;

import middlegen.*;
import middlegen.javax.JavaColumn;
import middlegen.javax.Sql2Java;
import middlegen.plugins.hibernate.interfaces.JavaTypeMapper;
import middlegen.util.BooleanNode;

// Referenced classes of package middlegen.plugins.hibernate:
//            HibernatePlugin

public class HibernateColumn extends JavaColumn
{

    private BooleanNode _updateable;
    private BooleanNode _insertable;
    private BooleanNode _incToString;
    private BooleanNode _genProperty;
    private BooleanNode _incEquals;
    private String _getScope;
    private String _setScope;
    private String _fieldScope;
    private String _accessField;
    private String _fieldDescription;
    private String _beanPropertyType;
    private String _columnSpecialty;

    public HibernateColumn(Column subject)
    {
        super(subject);
        _updateable = BooleanNode.createRoot(true);
        _insertable = BooleanNode.createRoot(true);
        _incToString = BooleanNode.createRoot(false);
        _genProperty = BooleanNode.createRoot(true);
        _incEquals = BooleanNode.createRoot(false);
    }

    public void setUpdateable(boolean flag)
    {
        setPrefsValue("updateable", Util.string(flag));
        _updateable.setValue(flag);
    }

    public void setInsertable(boolean flag)
    {
        setPrefsValue("insertable", Util.string(flag));
        _insertable.setValue(flag);
    }

    public void setIncludeToString(boolean flag)
    {
        setPrefsValue("inctostring", Util.string(flag));
        _incToString.setValue(flag);
    }

    public void setIncludeEquals(boolean flag)
    {
        setPrefsValue("incequals", Util.string(flag));
        _incEquals.setValue(flag);
    }

    public void setGenProperty(boolean flag)
    {
        setPrefsValue("genproperty", Util.string(flag));
        _genProperty.setValue(flag);
    }

    public void setFieldGetScope(String value)
    {
        setPrefsValue("getscope", value);
        _getScope = value;
    }

    public void setFieldSetScope(String value)
    {
        setPrefsValue("setscope", value);
        _setScope = value;
    }

    public void setFieldScope(String value)
    {
        setPrefsValue("fieldscope", value);
        _fieldScope = value;
    }

    public void setAccessField(String value)
    {
        setPrefsValue("accessfield", value);
        _accessField = value;
    }

    public void setFieldDescription(String value)
    {
        setPrefsValue("description", value);
        _fieldDescription = value;
    }

    public void setColumnSpecialty(String value)
    {
        setPrefsValue("columnspecialty", value);
        _columnSpecialty = value;
    }

    public void setBeanPropertyType(String value)
    {
        setPrefsValue("beanpropertytype", value);
        _beanPropertyType = value;
    }

    public boolean isUpdateable()
    {
        return _updateable.isCompletelyTrue();
    }

    public boolean isInsertable()
    {
        return _insertable.isCompletelyTrue();
    }

    public boolean isIncludeToString()
    {
        return _incToString.isCompletelyTrue();
    }

    public boolean isIncludeEquals()
    {
        return _incEquals.isCompletelyTrue();
    }

    public boolean isGenProperty()
    {
        return _genProperty.isCompletelyTrue();
    }

    public BooleanNode getUpdateableNode()
    {
        return _updateable;
    }

    public BooleanNode getInsertableNode()
    {
        return _insertable;
    }

    public BooleanNode getIncludeToStringNode()
    {
        return _incToString;
    }

    public BooleanNode getIncludeEqualsNode()
    {
        return _incEquals;
    }

    public BooleanNode getGenPropertyNode()
    {
        return _genProperty;
    }

    public String getFieldScope()
    {
        return _fieldScope.trim();
    }

    public String getAccessField()
    {
        return _accessField.trim();
    }

    public String getFieldGetScope()
    {
        return _getScope.trim();
    }

    public String getFieldSetScope()
    {
        return _setScope.trim();
    }

    public String getFieldDescription()
    {
        return _fieldDescription.trim();
    }

    public String getBeanPropertyType()
    {
        return _beanPropertyType.trim();
    }

    public String getColumnSpecialty()
    {
        return _columnSpecialty.trim();
    }

    public String getParseMethod()
    {
        if(isPrimitive())
            return String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(getClassForPrimitive())))).append(".parse").append(Util.capitalise(getJavaType()))));
        if("java.lang.String".equals(getJavaType()))
            return "";
        else
            return "new ".concat(String.valueOf(String.valueOf(getJavaType())));
    }

    public boolean isSized()
    {
        return super.getSize() != 0;
    }

    public boolean isSpecialtyProperty()
    {
        return _columnSpecialty.equals("property");
    }

    public boolean isSpecialtyVersionProperty()
    {
        return _columnSpecialty.equals("version");
    }

    public boolean isSpecialtyTimestampProperty()
    {
        return _columnSpecialty.equals("timestamp");
    }

    public boolean isMetaData()
    {
        return isIncludeToString() || isIncludeEquals() || isFieldScopeName() || isFieldGetScopeName() || isFieldSetScopeName() || isFieldDescriptionName() || isBeanPropertyTypeName() || !isGenProperty();
    }

    public boolean isAccessFieldName()
    {
        return _accessField != null && _accessField.trim().length() != 0 && !_accessField.equals("property");
    }

    public boolean isFieldScopeName()
    {
        return _fieldScope != null && _fieldScope.trim().length() != 0 && !_fieldScope.equals("private");
    }

    public boolean isFieldGetScopeName()
    {
        return _getScope != null && _getScope.trim().length() != 0 && !_getScope.equals("public");
    }

    public boolean isFieldSetScopeName()
    {
        return _setScope != null && _setScope.trim().length() != 0 && !_setScope.equals("public");
    }

    public boolean isFieldDescriptionName()
    {
        return _fieldDescription != null && _fieldDescription.trim().length() != 0;
    }

    public boolean isBeanPropertyTypeName()
    {
        return _beanPropertyType != null && !_beanPropertyType.equals("unbound");
    }

    public JavaTypeMapper getJavaTypeMapper()
    {
        return ((HibernatePlugin)getPlugin()).getJavaTypeMapper();
    }

    protected void setJavaType()
    {
        if(getPrefsValue("java-type") != null)
        {
            setJavaType(getPrefsValue("java-type"));
        } else
        {
            JavaTypeMapper javaTypeMapper = getJavaTypeMapper();
            if(javaTypeMapper == null)
                setJavaType(Sql2Java.getPreferredJavaType(getSqlType(), getSize(), getDecimalDigits()));
            else
                setJavaType(javaTypeMapper.getPreferredJavaType(this));
        }
    }

    protected void init()
    {
        super.init();
        HibernatePlugin plugin = (HibernatePlugin)getPlugin();
        _updateable.setValue(plugin.isColumnsUpdateable());
        if(getPrefsValue("updateable") != null)
            setUpdateable(Util.bool(getPrefsValue("updateable")));
        _insertable.setValue(plugin.isColumnsInsertable());
        if(getPrefsValue("insertable") != null)
            setInsertable(Util.bool(getPrefsValue("insertable")));
        _incEquals.setValue(plugin.isColumnsIncludeEquals());
        if(getPrefsValue("incequals") != null)
            setIncludeEquals(Util.bool(getPrefsValue("incequals")));
        _incToString.setValue(plugin.isColumnsIncludeToString());
        if(getPrefsValue("inctostring") != null)
            setIncludeToString(Util.bool(getPrefsValue("inctostring")));
        _genProperty.setValue(plugin.isColumnsGenProperty());
        if(getPrefsValue("genproperty") != null)
            setGenProperty(Util.bool(getPrefsValue("genproperty")));
        _accessField = plugin.getAccessField();
        if(getPrefsValue("accessfield") != null)
            setAccessField(getPrefsValue("accessfield"));
        _fieldScope = plugin.getFieldScope();
        if(getPrefsValue("fieldscope") != null)
            setFieldScope(getPrefsValue("fieldscope"));
        _getScope = plugin.getFieldGetScope();
        if(getPrefsValue("getscope") != null)
            setFieldGetScope(getPrefsValue("getscope"));
        _setScope = plugin.getFieldSetScope();
        if(getPrefsValue("setscope") != null)
            setFieldSetScope(getPrefsValue("setscope"));
        _fieldDescription = plugin.getFieldDescription();
        if(getPrefsValue("description") != null)
            setFieldDescription(getPrefsValue("description"));
        _beanPropertyType = plugin.getBeanPropertyType();
        if(getPrefsValue("beanpropertytype") != null)
            setBeanPropertyType(getPrefsValue("beanpropertytype"));
        _columnSpecialty = "property";
        if(getPrefsValue("columnspecialty") != null)
            setColumnSpecialty(getPrefsValue("columnspecialty"));
    }
}
